package com.kin207.netty.session;

import java.util.HashSet;
import java.util.Set;

import io.netty.channel.ChannelHandlerContext;

public class Session {
	
	private ISessionManager sessionManager;
	private ChannelHandlerContext channelHandlerContext;
	private String id;
	private String name;
	private Set<String> groups;
	private long lastActive;
	
	public Session() {
		super();
	}
	public Session(ChannelHandlerContext channelHandlerContext) {
		super();
		this.channelHandlerContext = channelHandlerContext;
	}
	public Session(ISessionManager sessionManager, ChannelHandlerContext channelHandlerContext) {
		super();
		this.sessionManager = sessionManager;
		this.channelHandlerContext = channelHandlerContext;
	}
	public Session(String id, ISessionManager sessionManager, ChannelHandlerContext channelHandlerContext) {
		super();
		this.id = id;
		this.sessionManager = sessionManager;
		this.channelHandlerContext = channelHandlerContext;
	}
	public Session(ChannelHandlerContext channelHandlerContext, String name, Set<String> groups) {
		super();
		this.channelHandlerContext = channelHandlerContext;
		this.name = name;
		this.groups = groups;
	}
	public Session(ISessionManager sessionManager, ChannelHandlerContext channelHandlerContext, String name, Set<String> groups) {
		super();
		this.sessionManager = sessionManager;
		this.channelHandlerContext = channelHandlerContext;
		this.name = name;
		this.groups = groups;
	}
	public ChannelHandlerContext getChannelHandlerContext() {
		return channelHandlerContext;
	}
	public void setChannelHandlerContext(ChannelHandlerContext channelHandlerContext) {
		this.channelHandlerContext = channelHandlerContext;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Set<String> getGroups() {
		return groups;
	}
	public void setGroups(Set<String> groups) {
		this.groups = groups;
	}
	
	public void addGroup(String groupName){
		if(groups==null){
			groups = new HashSet();
		}
		groups.add(groupName);
	}
	
	public void removeGroup(String groupName){
		if(groups!=null){
			groups.remove(groupName);
		}
	}
	public long getLastActive() {
		return lastActive;
	}
	public void setLastActive(long lastActive) {
		this.lastActive = lastActive;
	}
	public void lastActive() {
		this.lastActive = System.currentTimeMillis();
	}
	public ISessionManager getSessionManager() {
		return sessionManager;
	}
	public void setSessionManager(ISessionManager sessionManager) {
		this.sessionManager = sessionManager;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	
	
}
